package com.xr.generator.config;

import com.xr.generator.dao.*;
import com.xr.generator.utils.RRException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

/**
 * MYSQL数据库配置
 */
@Configuration
public class DbConfig {

    @Value("${xr.database}")
    private String database;

    @Autowired
    private MySQLGeneratorDao mySQLGeneratorDao;

    @Bean
    @Primary
    public GeneratorDao getGeneratorDao() {
        if ("mysql".equalsIgnoreCase(database)) {
            return mySQLGeneratorDao;
        } else {
            throw new RRException("不支持当前数据库：" + database);
        }
    }

}
